package org.kazuhiko.rpg.server.model;

import org.kazuhiko.rpg.server.net.RPGSession;
import org.kazuhiko.rpg.server.util.PlayerList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class World
{
	private static final Logger logger = LoggerFactory.getLogger( World.class );
	
	private PlayerList playerList = new PlayerList();
	
	public World()
	{
		init();
	}
	
	private void init()
	{
		//LETS PLAY FOR GOD AND INIT THE WORLD !
	}
	
	public PlayerList getPlayerList()
	{
		return playerList;
	}
	
	public void removePlayer( Player player )
	{
		logger.trace( "Removing player {" + player.getName() +"}" );
		playerList.remove( player );
	}
	
	public void addPlayer( Player player )
	{
		playerList.add( player );
	}
	
	public void completeLogin( RPGSession session )
	{
		session.getActionSender().sendChatMessage( "Welcome to Java RPG Beta!" );
	}
	
	public void broadcast( Player player, String message )
	{
		for( Player otherPlayer : playerList.getPlayers() )
		{
			otherPlayer.getSession().getActionSender().sendChatMessage( player.getId(), message );
		}
	}
	
	public void broadcast( String message )
	{
		for( Player player : playerList.getPlayers() )
		{
			player.getSession().getActionSender().sendChatMessage( message );
		}
	}
}
